/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.ytbolg.mcxa.gui;
//import com.github.to2mbn.jmccc.laun

import com.github.to2mbn.jmccc.auth.Authenticator;
import com.github.to2mbn.jmccc.auth.OfflineAuthenticator;
import com.github.to2mbn.jmccc.auth.YggdrasilAuthenticator;
import com.github.to2mbn.jmccc.auth.YggdrasilPasswordAuthenticator;
import com.github.to2mbn.jmccc.launch.Jmccc;
import com.github.to2mbn.jmccc.launch.LaunchException;
import com.github.to2mbn.jmccc.launch.Launcher;
import com.github.to2mbn.jmccc.option.LaunchOption;
import com.github.to2mbn.jmccc.option.MinecraftDirectory;
import com.github.to2mbn.jmccc.version.Version;
import com.github.to2mbn.jmccc.version.Versions;
import java.awt.TrayIcon;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import net.ytbolg.mcxa.gui.Lang_and_ConfigManager.Config;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
//import net.ytbolg.launcher.Laucher;
//import net.ytbolg.mcxa.CommonTools;
//import net.ytbolg.mcxa.General;
//import net.ytbolg.mcxa.Guide;
//import static net.ytbolg.mcxa.CommonTools.ReadFile;
import net.ytbolg.mcxa.gui.Lang_and_ConfigManager.LangManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author Ytong
 */
public class Main extends javax.swing.JFrame {
    
    public static JFrame me = null;

    /**
     * Creates new form Main
     */
    public Main() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu2 = new javax.swing.JPopupMenu();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jPasswordField1 = new javax.swing.JPasswordField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton6 = new javax.swing.JButton();

        jPopupMenu2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPopupMenu2MouseClicked(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jList1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jList1);

        jLabel1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel1.setText("玩家名");

        jTextField1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N

        jLabel2.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel2.setText("正版密码");

        jCheckBox1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jCheckBox1.setText("正版登陆/twitch");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jPasswordField1.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N

        jButton1.setFont(new java.awt.Font("微软雅黑", 0, 36)); // NOI18N
        jButton1.setText("启动");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jButton2.setText("下载中心");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jButton3.setText("检查更新");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jButton4.setText("关于");

        jLabel4.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel4.setText("附加参数");

        jLabel5.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel5.setText("版本类型");

        jLabel6.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jLabel6.setText("发布时间");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jComboBox1.setEditable(true);
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true" }));

        jButton6.setFont(new java.awt.Font("微软雅黑", 0, 12)); // NOI18N
        jButton6.setText("设置");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel4)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPasswordField1)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
                        .addComponent(jTextField1))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(22, 22, 22)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addComponent(jCheckBox1)
                .addGap(18, 18, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addGap(15, 15, 15)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton4)))
                .addGap(0, 43, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        try {
            me = this;
            setLocationRelativeTo(null);
            if (new File(General.ConfigDir).exists() == false) {
                setEnabled(false);
                new Guide().setVisible(true);
                //      Thread.yield();
            }
            Config.LoadConfig(new File(General.ConfigDir));
            //       Config.setConfig("Language", "2");
            LangManager.addLangData(Main.class.getClassLoader().getResourceAsStream("net/ytbolg/mcxa/gui/LangFiles/sChinese.lang"));
            LangManager.addLangData(Main.class.getClassLoader().getResourceAsStream("net/ytbolg/mcxa/gui/LangFiles/tChinese.lang"));
            LangManager.addLangData(Main.class.getClassLoader().getResourceAsStream("net/ytbolg/mcxa/gui/LangFiles/English.lang"));
            
            LangManager.Load(Integer.parseInt(Config.getConfigToString("Language")));
            setTitle("MCLauncherXA " + General.AppVersion + " by officeyutong");
            
            LoadConfig();
            LoadLanguage();
            AddMenu();
//System.out.println(Arrays.toString());
            jList1.setListData(CommonTools.ListMinecraftVersions(new File(General.GameDir)));
            
            General.Log("AppDir=" + General.AppDir, Main.class.getSimpleName());
            General.Log("GameDir=" + General.GameDir, Main.class.getSimpleName());
            General.Log("ConfigDir=" + General.ConfigDir, Main.class.getSimpleName());
            General.Log("Selected language=" + LangManager.getNameById(Integer.parseInt(Config.getConfigToString("Language"))), Main.class.getSimpleName());
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_formWindowOpened

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if (jCheckBox1.isSelected()) {
            jPasswordField1.setEnabled(true);
        } else {
            jPasswordField1.setEnabled(false);
        }   // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        new DownloadCenter().setVisible(true);
        setEnabled(false);// TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
        if (jList1.getSelectedIndex() < 0) {
            return;
        }
        if (evt.getButton() == MouseEvent.BUTTON3) {
            jPopupMenu2.show(jList1, evt.getX(), evt.getY());
        }
        
        CommonTools.MCInfo in = CommonTools.getMCInfo(jList1.getSelectedValue().toString());
        jLabel7.setText(in.getVersionType());
// TODO add your handling code here:
        jLabel8.setText(in.getRelTime());
    }//GEN-LAST:event_jList1MouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (jList1.getSelectedIndex() < 0) {
            JOptionPane.showMessageDialog(rootPane, LangManager.getStringByKey("请选择版本"), LangManager.getStringByKey("错误"), JOptionPane.ERROR_MESSAGE);
            return;
        }
        try {
            Launcher l = Jmccc.getLauncher();
            Authenticator auth = null;
            if (Config.getConfig("OnlineUse").equals("true")) {
                auth = new YggdrasilPasswordAuthenticator(jTextField1.getText(), new String(jPasswordField1.getPassword()));
            } else {
                auth = new OfflineAuthenticator(jTextField1.getText());
            }
            MinecraftDirectory dir = new MinecraftDirectory((String) Config.getConfig("MinecraftDir"));
            //      JSONObject jo = new JSONObject(CommonTools.ReadFile(dir.getVersionJson(jList1.getSelectedValue().toString()).getPath()));
            LaunchOption lo = new LaunchOption(Versions.resolveVersion(dir, jList1.getSelectedValue().toString()), auth);

            //Version v=new Version(jo.getString("id"),jo.getString("mainClass"),jo.getString("assets"), null, null, null, rootPaneCheckingEnabled);
            l.launch(lo);
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JSONException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (LaunchException ex) {
            JOptionPane.showMessageDialog(rootPane, "启动失败:\n" + ex.getMessage() + ex.getLocalizedMessage(), "错误", JOptionPane.ERROR_MESSAGE);
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jPopupMenu2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPopupMenu2MouseClicked

        // TODO add your handling code here:
    }//GEN-LAST:event_jPopupMenu2MouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton jButton1;
    public javax.swing.JButton jButton2;
    public javax.swing.JButton jButton3;
    public javax.swing.JButton jButton4;
    public javax.swing.JButton jButton6;
    public javax.swing.JCheckBox jCheckBox1;
    public javax.swing.JComboBox jComboBox1;
    public javax.swing.JLabel jLabel1;
    public javax.swing.JLabel jLabel2;
    public javax.swing.JLabel jLabel4;
    public javax.swing.JLabel jLabel5;
    public javax.swing.JLabel jLabel6;
    public javax.swing.JLabel jLabel7;
    public javax.swing.JLabel jLabel8;
    public javax.swing.JList jList1;
    public javax.swing.JPanel jPanel1;
    public javax.swing.JPasswordField jPasswordField1;
    public javax.swing.JPopupMenu jPopupMenu2;
    public javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
void LoadConfig() {
        General.Log("加载配置中..", Main.class.getSimpleName());
        jList1.setSelectedIndex(Integer.parseInt(Config.getConfigToString("LastLaunchVersionID")));
        jTextField1.setText(Config.getConfigToString("UserName"));
        jCheckBox1.setSelected(Config.getConfigToString("OnlineUse").equals("true"));
        jPasswordField1.setText(Config.getConfigToString("OnlinePassword"));
        if (jCheckBox1.isSelected()) {
            jPasswordField1.setEnabled(true);
        } else {
            jPasswordField1.setEnabled(false);
        }
        General.GameDir = Config.getConfigToString("MinecraftDir");
        
    }
    
    void LoadLanguage() {
        jLabel1.setText(LangManager.getStringByKey(jLabel1.getText()));
        jLabel2.setText(LangManager.getStringByKey(jLabel2.getText()));
        //   jLabel3.setText(LangManager.getStringByKey(jLabel3.getText()));
        jLabel4.setText(LangManager.getStringByKey(jLabel4.getText()));
        jLabel5.setText(LangManager.getStringByKey(jLabel5.getText()));
        jLabel6.setText(LangManager.getStringByKey(jLabel6.getText()));
//jLabel1.setText(LangManager.getStringByKey(jLabel1.getText()));
//jLabel1.setText(LangManager.getStringByKey(jLabel1.getText()));
        jCheckBox1.setText(LangManager.getStringByKey(jCheckBox1.getText()));
        jButton1.setText(LangManager.getStringByKey(jButton1.getText()));
        jButton2.setText(LangManager.getStringByKey(jButton2.getText()));
        jButton3.setText(LangManager.getStringByKey(jButton3.getText()));
        jButton4.setText(LangManager.getStringByKey(jButton4.getText()));
        jButton6.setText(LangManager.getStringByKey(jButton6.getText()));
    }
    
    public void AnalysisAssetsIndexes(String ver) {
        try {
            
            JSONObject main = new JSONObject(CommonTools.URLToString(DownloadSrc.getIndexesURL(ver)));
            General.Log(main.toString(), "Main");
            DownloadWindow dw = new DownloadWindow();
            File mainfol = null;
            if (main.has("virtual") && main.getBoolean("virtual")) {
                mainfol = new File(General.GameDir + General.separator + "assets" + General.separator + "virtual" + General.separator + ver + General.separator);
            } else {
                mainfol = new File(General.GameDir + General.separator + "assets");
            }
            JSONObject items = main.getJSONObject("objects");
            JSONArray item = items.names();
            General.Log("添加数目:" + item.length(), "Main");
            for (int i = 0; i < items.length(); i++) {
                JSONObject now = items.getJSONObject(item.getString(i));
                if (new File(mainfol + General.separator + "objects" + General.separator + now.getString("hash").substring(0, 2)).exists()) {
                    if (new File(mainfol + General.separator + "objects" + General.separator + now.getString("hash").substring(0, 2)).length() == now.getInt("size")) {
                        continue;
                    }
                }
                if (new File(mainfol.toString() + General.separator + item.get(i)).exists()) {
                    if (new File(mainfol.toString() + General.separator + item.get(i)).length() == now.getInt("size")) {
                        continue;
                    }
                }
                
                dw.addDownload(DownloadSrc.getAssetsURL() + now.getString("hash").substring(0, 2) + "/" + now.getString("hash"), mainfol + General.separator + "objects" + General.separator + now.getString("hash").substring(0, 2) + "/" + now.getString("hash"), mainfol.toString() + General.separator + item.get(i));
            }
            dw.setSelf(this);
            dw.setIfEnabld(true);
            setEnabled(false);
            
            new Thread(dw).start();
            dw.setVisible(true);
        } catch (JSONException | IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    void AddMenu() {
        JMenuItem it1 = jPopupMenu2.add(LangManager.getStringByKey("删除"));
        JMenuItem it2 = jPopupMenu2.add(LangManager.getStringByKey("下载资源"));
        JMenuItem it3 = jPopupMenu2.add(LangManager.getStringByKey("刷新"));
        
        it1.addMouseListener(new MouseListener() {
            
            @Override
            public void mouseClicked(MouseEvent e) {
                
            }
            
            @Override
            public void mousePressed(MouseEvent e) {
                //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            
            @Override
            public void mouseReleased(MouseEvent e) {
                System.out.println("- -");
                try {
                    if (jList1.getSelectedIndex() == -1) {
                        return;
                    }
                    String dir = General.GameDir + "/versions/" + jList1.getSelectedValue().toString();
                    CommonTools.deleteDir(new File(dir));
                    jList1.setListData(CommonTools.ListMinecraftVersions(new File(General.GameDir)));
                    //     throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
                //       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            
            @Override
            public void mouseEntered(MouseEvent e) {
                //       throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            
            @Override
            public void mouseExited(MouseEvent e) {
                //     throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        it2.addMouseListener(new MouseListener() {
            
            @Override
            public void mouseClicked(MouseEvent e) {

//      throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            
            @Override
            public void mousePressed(MouseEvent e) {
                //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            
            @Override
            public void mouseReleased(MouseEvent e) {
                JSONObject jo = null;
                String ver = "";
                try {
                    if (jList1.getSelectedIndex() == -1) {
                        return;
                    }
                    try {
                        jo = new JSONObject(CommonTools.ReadFile(General.GameDir + General.separator + "versions" + General.separator + jList1.getSelectedValue().toString() + General.separator + jList1.getSelectedValue().toString() + ".json"));
                    } catch (IOException ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    String version = jo.getString("id");
                    
                    if (version.contains("-")) {
                        version = version.substring(0, version.indexOf("-"));
                        
                    }
                    ver = version;
                    if (ver.length() < 3) {
                        ver = ver + "0";
                    }
                    version = version.replace(".", "");
                    if (Integer.parseInt(version) <= 172) {
                        ver = "legacy";
                    }
                    AnalysisAssetsIndexes(ver);      //      throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                } catch (JSONException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            
            @Override
            public void mouseEntered(MouseEvent e) {
                //      throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            
            @Override
            public void mouseExited(MouseEvent e) {
                //          throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        it3.addMouseListener(new MouseListener() {
            
            @Override
            public void mouseClicked(MouseEvent e) {
                
            }
            
            @Override
            public void mousePressed(MouseEvent e) {
                //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            
            @Override
            public void mouseReleased(MouseEvent e) {
                if (jList1.getSelectedIndex() == -1) {
                    return;
                }
                try {
                    jList1.setListData(CommonTools.ListMinecraftVersions(new File(General.GameDir)));
                    //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                }
                //      throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            
            @Override
            public void mouseEntered(MouseEvent e) {
                //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
            
            @Override
            public void mouseExited(MouseEvent e) {
                //   throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        
    }
}
